<template>
  <div class="layout-container" :class="{'old': elder}">
    <div class="layout-section">
      <div>
        <top-header :show-elder="false" :auth-check="true" @setElder="setElderByChild"></top-header>

        <apply-notice :user-type="6"></apply-notice>

        <div class="com-contain">
          <div style="padding: 8px 0">
            <div class="form-label">企业名称</div>
            <div class="form-input"><input type="text" :value="formData.unitName" readonly/></div>

            <upload-file ref="attr01" :caption="labels[params.userType].file1" fn="patch" file-type="01"
                         :unid="this.params.unid"></upload-file>

            <upload-file ref="attr02" :caption="labels[params.userType].file2" fn="patch" file-type="02"
                         :unid="this.params.unid"></upload-file>

            <upload-file ref="attr03" caption="法院或其它有效材料" fn="patch" file-type="03"
                         v-if="params.userType === '2'" :unid="this.params.unid"></upload-file>

            <div class="form-label">联系电话</div>
            <div class="form-input"><input type="text" :value="formData.mobile" readonly/></div>
          </div>
        </div>
        <div>
          <div class="form-btns">
            <button class="primary" @click="doSave">重新提交</button>
            <button @click="$router.push({path: '/list'})">返回列表</button>
          </div>
        </div>

        <footer-right></footer-right>
      </div>
    </div>

    <footer-nav :active-index="-1"></footer-nav>
  </div>
</template>

<script>
import {apiDoPatch, apiGetInfo} from "@/api/apply";
import TopHeader from "@/components/topHeader";
import FooterRight from "@/components/footerRight";
import FooterNav from "@/components/footerNav";
import ApplyNotice from "@/components/applyNotice";
import {ajaxUtils} from "@/utils/lwUtils";
import UploadFile from "@/components/uploadFile";

export default {
  components: {UploadFile, ApplyNotice, FooterNav, FooterRight, TopHeader},
  data() {
    return {
      elder: false,
      params: {
        unid: "", userType: 0,
      },
      formData: {
        applyfrom: "", mobile: "", usertype: 0, unitName: ""
      },
      labels: [
        {file1: "受托人身份证", file2: "法人委托书"},
        {file1: "工作证", file2: "单位介绍信"},
        {file1: "律师执业证", file2: "单位介绍信(法院委托书)"}
      ],
    }
  },
  created() {
    this.params.unid = this.$route.query.unid;
    this.params.userType = this.$route.query.usertype;
    apiGetInfo(this.params.unid).then(res => {
      if (ajaxUtils.checkFail(res.code, res.msg)) {
        this.formData = {applyfrom: "", mobile: "", usertype: 0, unitName: ""};
        return;
      }
      this.formData = res.data;
    }).catch(err => {
      ajaxUtils.showErr(err);
    });
  },
  methods: {
    doSave: function () {
      if (this.$refs.attr01.fileList.length === 0
          || this.$refs.attr02.fileList.length === 0
          || (this.formData.usertype === 2 && this.$refs.attr03.fileList.length === 0)) {
        this.$eraqDlg.warning("请将相应的申请材料补充完整");
        return;
      }

      apiDoPatch(this.params.unid).then(res => {
        if (ajaxUtils.checkFail(res.code, res.msg)) {
          return;
        }
        this.$router.push({path: "/list"});
      }).catch(err => {
        ajaxUtils.showErr(err);
      });
    },
    //子组件调用方法，设置老年模式
    setElderByChild: function (elder) {
      this.elder = elder;
    },
  }
}
</script>

<style lang='scss' scoped>
@import "src/css/home";

.layout-section {
  background: #f2f3f9;
}

.van-uploader__input-wrapper {
  width: 100% !important;
}
</style>
